/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ar.edu.utn.frsf.tpae.a2012.g03.model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author fededalla
 */
@Entity
@Table(name = "cta")
@Inheritance(strategy=InheritanceType.JOINED)
public abstract class Cuenta {
	@Id
	@Column(name = "cta_id")
    protected Integer ctaId;
	@Column(name = "cta_nro", nullable = false)
    private long ctaNro;
	@Column(name = "cta_fech_ape", nullable = false)
    private Date ctaFechApe;
	@Column(name = "cta_sdo_act", nullable = false)
    private double ctaSdoAct;
	@OneToMany(cascade = CascadeType.ALL, mappedBy = "movCtaId")
    private List<Movimiento> movList;
	/*@OneToOne(cascade = CascadeType.ALL, mappedBy = "cta")
    private CuentaCorriente ctaCte;
	@OneToOne(cascade = CascadeType.ALL, mappedBy = "cta")
    private CajaAhorro cjaAho;*/
	@JoinColumn(name = "cta_cli_id", referencedColumnName = "cli_id")
    @ManyToOne(optional = false)
    private Cliente ctaCliId;

    public Cuenta() {
    }

    public Cuenta(Integer ctaId) {
        this.ctaId = ctaId;
    }

    public Cuenta(Integer ctaId, long ctaNro, Date ctaFechApe, double ctaSdoAct, Cliente ctaCliId) {
        this.ctaId = ctaId;
        this.ctaNro = ctaNro;
        this.ctaFechApe = ctaFechApe;
        this.ctaSdoAct = ctaSdoAct;
        this.ctaCliId = ctaCliId;
        this.movList = new ArrayList<Movimiento>();
    }

    public Integer getCtaId() {
        return ctaId;
    }

    public long getCtaNro() {
        return ctaNro;
    }

    public void setCtaNro(long ctaNro) {
        this.ctaNro = ctaNro;
    }

    public Date getCtaFechApe() {
        return ctaFechApe;
    }

    public void setCtaFechApe(Date ctaFechApe) {
        this.ctaFechApe = ctaFechApe;
    }

    public double getCtaSdoAct() {
        return ctaSdoAct;
    }

    public void setCtaSdoAct(double ctaSdoAct) {
        this.ctaSdoAct = ctaSdoAct;
    }

    @XmlTransient
    public List<Movimiento> getMovList() {
        return movList;
    }

    public void setMovList(List<Movimiento> movList) {
        this.movList = movList;
    }

    public Cliente getCtaCliId() {
        return ctaCliId;
    }

    public void setCtaCliId(Cliente ctaCliId) {
        this.ctaCliId = ctaCliId;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (ctaId != null ? ctaId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Cuenta)) {
            return false;
        }
        Cuenta other = (Cuenta) object;
        if ((this.ctaId == null && other.ctaId != null) || (this.ctaId != null && !this.ctaId.equals(other.ctaId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "model.Cta[ ctaId=" + ctaId + " ]";
    }
    
}

